package softdone;


import java.sql.CallableStatement;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collection;
import softdata.Pla_item;

public class Pla_done {
	public Collection Plates; 
	public int Num_Page=0;
	public void Pla_Read(int page){
		String sql="{call plates_read(?)}";
		try{
			Plates=new ArrayList();
			Num_Page=0;
			Conn dataconn=new Conn();
			dataconn.Create();
			CallableStatement cs=dataconn.CSt_SQL(sql);
			cs.setInt(1,page);
			ResultSet rs=cs.executeQuery();
			while(rs.next()){
				Pla_item platedata=new Pla_item();
				platedata.ID=rs.getInt(1);
				platedata.Nam_Plate=rs.getString(2);
				platedata.Num_Post=rs.getInt(3);
				platedata.Num_Clicks=rs.getInt(4);
				Num_Page++;
				Plates.add(platedata);
			}
			rs.close();
		    dataconn.CloseCC();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public int Num_Plates(){
		int NUM=0;
		String sql="{call plates_sum(?)}";
		try{
			Conn dataconn=new Conn();
			dataconn.Create();
			CallableStatement cs=dataconn.CSt_SQL(sql);
			cs.registerOutParameter(1,java.sql.Types.INTEGER);
			cs.execute();
			NUM=cs.getInt(1);
			dataconn.CloseCC();
		}catch(Exception e){
			e.printStackTrace();
		}
		return NUM;
	}
	public void Plate_edit(int id,String name){
		String sql="{call plates_edit(?,?)}";
		try{
			Conn dataconn=new Conn();
			dataconn.Create();
			CallableStatement cs=dataconn.CSt_SQL(sql);
			cs.setInt(1,id);
			cs.setString(2,name);
			cs.execute();
			dataconn.CloseCC();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public void Plate_delete(int id){
		String sql="{call plates_delete(?)}";
		try{
			Conn dataconn=new Conn();
			dataconn.Create();
			CallableStatement cs=dataconn.CSt_SQL(sql);
			cs.setInt(1,id);
			cs.execute();
			dataconn.CloseCC();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public void Plate_new(String name){
		String sql="{call plates_insert(?)}";
		try{
			Conn dataconn=new Conn();
			dataconn.Create();
			CallableStatement cs=dataconn.CSt_SQL(sql);
			cs.setString(1,name);
			cs.execute();
			dataconn.CloseCC();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
